package com.example.parkingproject.service.serviceImp;

import com.example.parkingproject.code.ServiceCode;
import com.example.parkingproject.ex.ServiceException;
import com.example.parkingproject.jopo.vo.BlackVo;
import com.example.parkingproject.mapper.BlackMapper;
import com.example.parkingproject.service.BlackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlackServiceImp implements BlackService {

    @Autowired
    BlackMapper blackMapper;

    @Override
    public List<BlackVo> getList() {
        List<BlackVo> list = blackMapper.getList();
        if (list.size()==0){
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND,"暂时没有黑名单数据");
        }
        return list;
    }

    @Override
    public List<BlackVo> search(String carId) {
        List<BlackVo> list = blackMapper.search(carId);
        if (list.size()==0){
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND,"查询数据不存在");
        }
        return list;
    }

    @Override
    public void delete(Integer id) {
        BlackVo blackVo = blackMapper.getBlack(id);
        if (blackVo==null){
            throw new ServiceException(ServiceCode.error_bad_request,"尝试移除的数据不存在请核对");
        }
        blackMapper.delete(id);
    }
}
